using System;
using System.Collections.Generic;
using TTDotNet.Util;

namespace TTDotNet.Engine.Terrain
{
    public class CornerSet
    {
        private Corner[] corners;

        public CornerSet()
        {
            this.corners = new Corner[4];
        }

        #region Constructors
        public CornerSet(int neCorner, int seCorner, int swCorner, int nwCorner)
        {
            this.corners = new Corner[4];
            corners[0] = new Corner(neCorner, Direction.NE);
            corners[1] = new Corner(seCorner, Direction.SE);
            corners[2] = new Corner(swCorner, Direction.SW);
            corners[3] = new Corner(nwCorner, Direction.NW);
        }

        public CornerSet(Corner neCorner, Corner seCorner, Corner swCorner, Corner nwCorner)
        {
            this.corners = new Corner[4];
            corners[0] = neCorner;
            corners[1] = seCorner;
            corners[2] = swCorner;
            corners[3] = nwCorner;
        }

        public CornerSet(Corner[] heights)
        {
            this.corners = new Corner[heights.Length];

            for (int i = 0; i < heights.Length; i++)
            {
                corners[i] = heights[i];
            }
        } 
        #endregion

        public void SetHeight(Direction dir, int height)
        {
            switch (dir)
            {
                case Direction.NE: corners[0].Height = height; break;
                case Direction.SE: corners[1].Height = height; break;
                case Direction.SW: corners[2].Height = height; break;
                case Direction.NW: corners[3].Height = height; break;
            }
        }

        public Corner NorthEast
        {
            get { return corners[0]; }
        }

        public Corner SouthEast
        {
            get { return corners[1]; }
        }

        public Corner SouthWest
        {
            get { return corners[2]; }
        }

        public Corner NorthWest
        {
            get { return corners[3]; }
        }


        public IEnumerator<Corner> GetEnumerator()
        {
            foreach (Corner corner in corners)
            {
                yield return corner;
            }
        }

    }
}
